// pages/Main/mainIndex/mainIndex.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    content:[],
    userid:"",
    orgid:"",
    ryid:"",
    title:"",
    workid:"",
    num: 1,
    scrollHeight: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      ryid: options.id,
      orgid: c.orgid,
      userid: c.userid,
      scrollHeight: scrollHeight,
    });
    this.list();
  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.list();
    } else {
      common.showToast("到底了", "loading");
    }
  },
  //6.2.1查询学生人员信息列表
  list:function () {
    // 第二步 传参
    common.showToast("加载中", "loading");
    let params = {
      "page": this.data.num, "num": 10, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "departmentid,type", "searchValue": "" + this.data.ryid + ",077ba48e-76f8-4afd-8a84-67b4f2ed3762"}
    //第三步 调用接口
    businessLogic.QueryStudentlist(params, (res) => {
      //console.log("2.2.1", res)
      //第五步 把获取的值，传入data
      var page=res.page
      var res=res.infos
      var bbb = this.data.content
      for (var a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      }
      this.setData({
        content: bbb,
        lenpage: page.pages
      });
    });
  },
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },
  bindKeyInput2: function (e) {
    this.setData({
      workid: e.detail.value
    })
  },
  /* search: function (event) {
    this.setData({
      title: event.detail.value

    })
    // console.log(event.detail.value )
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "title,workid,departmentid,type", "searchValue": ""+this.data.workid+","+this.data.title+","+this.data.ryid+",1c7fea3a-a277-4a18-8eb5-1a8a5d6b6971" }
    businessLogic.QueryStudentlist(params, (res) => {
      this.setData({
        content: res
      });
    });
  }, */
  search2: function (event) {
    let params = {
      "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "workid,title,departmentid,type", "searchValue": "" + this.data.workid + "," + this.data.title + "," + this.data.ryid + ",077ba48e-76f8-4afd-8a84-67b4f2ed3762"}
    businessLogic.QueryStudentlist(params, (res) => {
      var res = res.infos;
      this.setData({
        content: res
      });
    });
  },
  

  teacher: function () {
    wx.navigateTo({
      url: "../teacherOrder/teacherOrder"
    });
  }, parents: function () {
    wx.navigateTo({
      url: "../post/post"
    });
  }, student: function () {
    wx.navigateTo({
      url: "../post/post"
    });
  },
  studenPage: function (event) {
    wx.navigateTo({
      url: "../studenPage/studenPage?id=" + event.currentTarget.dataset.id
    });
   console.log(event.currentTarget.dataset.id)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})